from flask import Blueprint
from flask import redirect
from flask import request
from flask import session
from flask import url_for

admin_blu = Blueprint("admin", __name__, url_prefix="/admin")

from . import views


@admin_blu.before_request
def check_admin():
    # 如果不是管理员，直接到主页面
    is_admin = session.get("is_admin", False)
    # 不是管理员并且访问的不是登陆页面
    # if not is_admin and not request.url.endswith("admin/login"):
    if not is_admin and not request.url.endswith(url_for('admin.admin_login')):
        return redirect("http://127.0.0.1:5000/")
    else:
        print("看看")